package edu.purdue.cs.aggr.message;

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.UUID;

public abstract class Message implements Externalizable {

	private String id = null;
	private String sender = null;
	private String destination = null;
	
	@Override
	public void readExternal(ObjectInput in) throws IOException,
			ClassNotFoundException {
		id = (String) in.readObject();
		sender = (String) in.readObject();
		destination = (String) in.readObject();
	}

	@Override
	public void writeExternal(ObjectOutput out) throws IOException {
		out.writeObject(id);
		out.writeObject(sender);
		out.writeObject(destination);
	}
	
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	
	public Message() {
		id = UUID.randomUUID().toString();
	}
	
	public void setDestination(String d) {
	  this.destination = d;
	}
	
	public String getDestination() {
	  return destination;
	}
	
	public String getSender() {
		return sender;
	}
	
	public void setSender(String sender) {
		this.sender = sender;
	}
	
	public String toString() {
	  return "MESSAGE: id: " + id + " sender: " + sender + " dest: " + destination;
	}
}
